﻿

function MyPostBack(eventTarget, eventArgument) {
   
    var thForm = document.forms[0];    
    //thForm = document.form1;

    if (!thForm.onsubmit || (thForm.onsubmit() != false)) 
    {
        thForm.__EVENTTARGET.value = eventTarget;
        thForm.__EVENTARGUMENT.value = eventArgument;
        thForm.submit();
    }
}

function GetScreen_H() {
    return parseInt(window.screen.height)-275;
}

function GetScreen_W() {
    return parseInt(document.body.clientWidth)-10;
}

function OnDeleteClick() {
    return confirm('Удалить запись?');
}
function Set_Size(ControlId) {
    var h = GetScreen_H();
    $("#" + ControlId).height(h);

}


function ShowAlert() {    
    $(".msgAlert").show();
}
function HideAlert() {

    ResetLock();
    $(".msgAlert").hide();
}

function skm_LockScreen() {

    HideAlert();

    var lock = document.getElementById('skm_LockPane');
    if (lock)
       lock.className = 'LockOn';
}

function GrayLockScreen() {

    var lock = document.getElementById('GrayLockPanel');
    if (lock)
        lock.className = 'PopupWindowBackGround';

}


function ResetLock() {

    var lock = document.getElementById('skm_LockPane');
    if (lock)
        lock.className = 'LockOff';

    
}



//TreeDictionary ClientFunctions

function OnSelRbNode(ChId, DivId, ClassId, HfId) {

    var s = "." + ClassId;
       $(s).each(function() { this.checked = false; });
    $("#" + HfId)[0].value = ChId;
    $('#' + ChId)[0].checked = true;
    

}


function SetActiveNode(ID) {
    $('.TreeNodeActive').each(function() { $('#' + this.id).removeClass(); $('#' + this.id).addClass("TreeNode"); });
    $("#" + ID).removeClass();
    $("#" + ID).addClass("TreeNodeActive");
     
}


function showTreeBranch(sUrl, SelectedNodeId) {

        SetActiveNode(SelectedNodeId);
        var s = sUrl.replace('&', "|");
        parent.BranchContent.location = "PageProcessor.aspx?Page=" + s;

    }

    function OnTreeLabelClick(ChTree_CSS, ChTree_CSS_Selected, DIV_ID, LB_ID, SelectedNodeID) {
        alert('sss');
                selector = "div#"+DIV_ID + " ." + ChTree_CSS_Selected
                $(selector).each(function() {
                    if (this.id.length > 0)
                        $("." + this.id).removeClass(ChTree_CSS_Selected);
                });
                $("#" + LB_ID).addClass(ChTree_CSS_Selected);
                $("#" + SelectedNodeID)[0].value = LB_ID;

    }

    function Redirect(URL) {
        document.location = URL;

    }


    function onSelectBranch(sURL, nodeCSS, selCSS, NodeId) {

        var s = "." + selCSS;
        

        $(s).each(function() { $('#' + this.id).removeClass(selCSS); });

        $('#' + NodeId).addClass(selCSS);

        var sURL = sURL.replace('&', "|");
        parent.BranchContent.location= "PageProcessor.aspx?Page=" + sURL;
    }   


//TreeDictionary ClientFunctions end



function GrdItemOnMouseOver(obj) {
    obj.style.backgroundColor = 'rgb(240, 240, 240)'; obj.style.cursor = 'pointer';
}

function GrdItemOnMouseOut(obj) {
    obj.style.backgroundColor = ''; obj.style.cursor = '';
}

function CaptionToggle(Caption_ID, Arrow_ID) {
    var cCss = $('#' + Arrow_ID).attr("class");
    $('#' + Arrow_ID).removeClass();
    if (cCss == "ArrowUP")
        $('#' + Arrow_ID).addClass("ArrowDown");
    else
        $('#' + Arrow_ID).addClass("ArrowUP");

    $('#' + Caption_ID).slideToggle('fast');
}




/*
------------------------------------------
Google Maps Functions
-------------------------------------
*/

function createMarker(point, index) {
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml("<b>" + index + "</b>");
    });
    return marker;
}

function InitMap(DivId, lat, lng, MapSize) {

    map = new GMap2(document.getElementById(DivId));
    map.setUIToDefault();
    map.setCenter(new GLatLng(lat, lng), MapSize);
}

function AddPoint_Editmode(lat, lng) 
{
    var latlng = new GLatLng(lat, lng);
    var point = new GLatLng(pnt.lat, pnt.lng);
    var marker = createMarker(point,'' );
    map.addOverlay(marker);
}

function AddListner_PointEditMode() {
    GEvent.addListener(map, "click", function(marker, point) {
        map.clearOverlays();

        if (marker) {
            map.removeOverlay(marker);
        } else {
            map.addOverlay(new GMarker(point));
        }
    }
           );
     
}

/*
------------------------------------------
Cookies and Misc Functions
-------------------------------------
*/
// Set cookie on each event
// Function to set the Toc panel size
// Browser must support cookies and script
function SetTocPanelCookie(sName, sValue, days) {
    if (window.navigator.cookieEnabled == true) {
        var expires = ";";
        if (days > 0) {
            var cookieDate = new Date();
            cookieDate.setTime(cookieDate.getTime() + (days * 24 * 360000));
            expires = "; expires=" + cookieDate.toGMTString();
        }
        var CookieInfo = sName + "=" + escape(sValue) + "; expires=-1" + "; path=/";
        document.cookie = CookieInfo;

        var CookieInfo = sName + "=" + escape(sValue) + expires + "; path=/";
        document.cookie = CookieInfo;
    }
    return;
}

// Function to get the Toc panel size
// Browser must support cookies and script
// Special for VS, by default do not show the TOC on first instance,
// and support the cookie state on subsquent pages
function GetTocPanelCookie(sName) {
    var currentTocWidth = -1;
    var allCookie = String(document.cookie);
    var pos = allCookie.indexOf(sName);
    //  alert(window.history.length);

    if (document.referrer == "" && ideUA == true && window.history.length == 0) {
        SetTocPanelCookie(cookieName, "0px", days);
        return currentTocWidth;
    }
    else {
        if (pos != -1) {
            var tocValue = allCookie.split("; ");

            for (i = 0; i < tocValue.length; i++) {
                var cookieValue = tocValue[i].split("=");
                if (sName == cookieValue[0]) {
                    currentTocWidth = cookieValue[1];
                    break;
                }
            }
        }
    }
    return currentTocWidth;
}


function CallTest() {
    ws_Hints.TestString(OnMethodSucceeded_Test, OnMethodFailed);
}

/*------------------------------------------------------------------------------------------------------------------------------------------------
                                                                    SideShedule 
------------------------------------------------------------------------------------------------------------------------------------------------*/

function CallWS_AddSurfaceItem(SideId, CellFirstDay, CellLastDay) {


    ws_SheduleFace.AddSurfaceItem(SideId,
                                    ContractID,
                                    CellFirstDay,
                                    CellLastDay,
                                    $("#" + DtStart_ID)[0].value,
                                    $("#" + DtEnd_ID)[0].value,
                                    $("#" + PeriodType_ID).val(),
                                    OnMethodSucceeded_RefreshSide,
                                    OnMethodFailed);

}


function CallWS_RefreshSide(SideId, CellFirstDay, CellLastDay) {


    ws_SheduleFace.RefreshSide(SideId,
                                    ContractID,
                                    CellFirstDay,
                                    CellLastDay,
                                    $("#" + DtStart_ID)[0].value,
                                    $("#" + DtEnd_ID)[0].value,
                                    $("#" + PeriodType_ID).val(),
                                    OnMethodSucceeded_RefreshSide,
                                    OnMethodFailed);

}

function OnMethodSucceeded_RefreshSide(result, eventArgs) {

    $("." + result.SideId)[0].innerHTML = result.Html;
}




function OnPeriodChange() {

    ws_Hints.SetEditingPeriod($("#" + PeriodType_ID).val(), $("#" + DtStart_ID)[0].value, $("#" + DtEnd_ID)[0].value, OnMethodSucceeded_OnPeriodChange, OnMethodFailed);
}

function OnMethodSucceeded_OnPeriodChange(result, eventArgs) {
    $("#" + DtStart_ID)[0].value = result.dtStart;
    $("#" + DtEnd_ID)[0].value = result.dtEnd;
}

function OnMethodFailed(error) {
    alert(error.get_message());
}


function OnMethodSucceeded_Test(result, eventArgs) {
    alert(result);
}



/*
----------------------------------SideShedule----------------------------------------
*/
function RefreshRow (dtStart, dtEnd, SideId) {

    PageMethodsParams.TimeLine_dtStart = dtStart;
    PageMethodsParams.TimeLine_dtEnd = dtEnd;
    PageMethodsParams.SideId = SideId;
    //  PageMethods.CallRefreshRow(PageMethodsParams, RefreshRowComplete)
    WS_UIHelper.CallRefreshRow(PageMethodsParams, RefreshRowComplete)
  }

function RefreshRowComplete(result) {
    if (result != "")
        $("#Shedule_" + PageMethodsParams.SideId).html(result);
}


